package com.woniuxy.mapper;

import com.woniuxy.entity.Communicate;
import com.woniuxy.entity.CommunicateExample;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


/*
@author Jan
@create 2020-05-27 17:37

*/ 
   
public interface CommunicateMapper {
    long countByExample(CommunicateExample example);

    int deleteByExample(CommunicateExample example);

    int deleteByPrimaryKey(Integer communicateId);

    int insert(Communicate record);

    int insertSelective(Communicate record);

    List<Communicate> selectByExample(CommunicateExample example);

    Communicate selectByPrimaryKey(Integer communicateId);

    int updateByExampleSelective(@Param("record") Communicate record, @Param("example") CommunicateExample example);

    int updateByExample(@Param("record") Communicate record, @Param("example") CommunicateExample example);

    int updateByPrimaryKeySelective(Communicate record);

    int updateByPrimaryKey(Communicate record);

    @Select(" select COUNT(1) from "
            +" (select * from communicate c where c.permisson = 0"
            +" UNION"
            +" SELECT c.* from communicate c left join friend_ship f on c.user_id = f.user_id where f.f_user_id = #{userId} and c.permisson = 1"
            +" UNION"
            +" select c.* from communicate c where c.permisson = 2 and c.camp_id = #{campId}"
            +" UNION"
            +" select * from ("
            +" select c.* from communicate c where c.permisson = 3 and c.camp_id = #{campId}"
            +" UNION"
            +" SELECT c.* from communicate c left join friend_ship f on c.user_id = f.user_id where f.f_user_id = #{userId} and c.permisson = 1"
            +" )s)s1")
    long queryCanSeeDetailCount(Integer userId, Integer campId);

    List<Map<String, Object>> queryCanSeeDetailLimit(HashMap<String, Object> map);
}